<#assign ctx=springMacroRequestContext.contextPath/>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>首页--layui后台管理模板 2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctx}/style/font/font.css"/>
    <link rel="stylesheet" href="${ctx}/plugin/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctx}/plugin/layer/theme/default/layer.css"/>
</head>
<body>
<input id="basePath" type="hidden" value="${ctx}"/>
<form class="layui-form">
    <br>
    <div class="layui-form-item">
        <label class="layui-form-label">旧的密码</label>
        <div class="layui-input-inline" style="margin-right: 30px">
            <input type="password" class="layui-input" placeholder="请输入原来旧密码"
                   lay-verify="required" id="oldPass">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新的密码</label>
        <div class="layui-input-inline" style="margin-right: 30px">
            <input type="password" class="layui-input" placeholder="请输入新的密码"
                   lay-verify="required" id="newPass">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline" style="margin-right: 30px">
            <input type="password" class="layui-input" placeholder="请再次输入新密码"
                   lay-verify="required" id="curPass">
        </div>
    </div>
    <div class="layui-form-item" style="text-align:center; width:100%;position:fixed; bottom:0;">
        <input type="button" value="修改" class="layui-btn layui-btn-sm" lay-filter="userPassBtn" lay-submit/>
        <input type="button" id="backRoleBtn" value="取消" class="layui-btn layui-btn-sm layui-btn-warn"/>
    </div>
</form>

<script type="text/javascript" src="${ctx}/plugin/jquery/jquery.min-1.9.1.js"></script>
<script type="text/javascript" src="${ctx}/plugin/layui/layui.js"></script>
<script type="text/javascript" src="${ctx}/plugin/layer/layer.js"></script>
<script>
    var basePath = $("#basePath").val();
    $(document).ready(function () {
        layui.use('form', function () {
            var form = layui.form;
            //渲染表单
            form.render();
            //监听提交
            form.on('submit(userPassBtn)', function (data) {
                submitUserPassForm();
                return false;
            });
        });
        //注册监听事件
        $("#backRoleBtn").on("click", function () {
            //关闭弹出层
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
    });

    function submitUserPassForm() {
        $.ajax({
            type: "post",
            url: basePath + '/sys/user/change',
            data: {
                "oldPass": $("#oldPass").val(),
                "newPass": $("#newPass").val(),
                "curPass": $("#curPass").val()
            },
            success: function (data) {
                var currLayer = layer.alert(data.msgs, {
                    skin: 'layui-layer-molv',
                    closeBtn: 0
                }, function () {
                    if (data.code == 200) {
                        //关闭弹出层
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        //退出系统
                        window.location.href = basePath + "/logout";
                        parent.location.reload();
                    } else {
                        layer.close(currLayer);
                    }
                });
            }
        });
    }
</script>
</body>
</html>